﻿using System;
using System.IO;

using RayDen.Library.Data.Xml;
using RayDen.Library.Entity.Frames;

namespace UITools
{
    public class FrameController
    {
        public FrameDescription Frame;

        public string FrameSource
        {
            get { return SerializationService.Serialize(Frame); }
            set { this.Frame = (FrameDescription)SerializationService.Deserialize(value, typeof(FrameDescription)); }
        }

        public FrameController(){}

        public void Open(string frameName)
        {
            FrameDescription frame = null;

            using (var frameFile = new FileStream(frameName, FileMode.Open, FileAccess.Read))
            {
                using (var reader = new StreamReader(frameFile))
                    frame = (FrameDescription)SerializationService.Deserialize(reader.ReadToEnd(), typeof(FrameDescription));
            }
            frame.FrameName = Path.GetFileNameWithoutExtension(frameName);
            this.Frame = frame;
        }


    }
}
